
#include "atomic_op_namespace.h"

#include <sys/atomic.h>

uint16_t fetch_and_xor_2(volatile uint16_t *, uint16_t, ...)
    asm("__sync_fetch_and_xor_2");
uint16_t xor_and_fetch_2(volatile uint16_t *, uint16_t, ...)
    asm("__sync_xor_and_fetch_2");

uint16_t
fetch_and_xor_2(volatile uint16_t *addr, uint16_t val, ...)
{
	uint16_t old, new;

	do {
		old = *addr;
		new = old ^ val;
	} while (atomic_cas_16(addr, old, new) != old);
	return old;
}

uint16_t
xor_and_fetch_2(volatile uint16_t *addr, uint16_t val, ...)
{
	uint16_t old, new;

	do {
		old = *addr;
		new = old ^ val;
	} while (atomic_cas_16(addr, old, new) != old);
	return new;
}

__strong_alias(__atomic_fetch_xor_2,__sync_fetch_and_xor_2)
